-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added lazy sync functionality #279
Added lazy sync functionality #279
Conversation
…has changed since the last sync. Added extra field to lock file in order to keep track of config changes. Signed-off-by: Fritz Durchardt <[email protected]>
edd9918
to
5d8f4d2
Compare
Signed-off-by: Fritz Durchardt <[email protected]>
Signed-off-by: Fritz Durchardt <[email protected]>
Signed-off-by: Fritz Durchardt <[email protected]>
pkg/vendir/cmd/sync.go
Outdated
@@ -50,6 +51,7 @@ func NewSyncCmd(o *SyncOptions) *cobra.Command { | |||
|
|||
cmd.Flags().StringSliceVarP(&o.Directories, "directory", "d", nil, "Sync specific directory (format: dir/sub-dir[=local-dir])") | |||
cmd.Flags().BoolVarP(&o.Locked, "locked", "l", false, "Consult lock file to pull exact references (e.g. use git sha instead of branch name)") | |||
cmd.Flags().BoolVar(&o.Eager, "eager", false, "Ignore lazy setting in vendir yml and eagerly fetch all remote content") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we decide to have default functionality of vendir to fetch only if vendir.yaml has changed else ignore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proposal is already open. I think the default will remain unchanged, but if you have this new feature enabled via vendir.yaml config, you can opt out by setting the eager flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kumaritanushree the default behavior will not change - vendir will always fetch. However, if the user sets lazy to true in the vendir.yaml for a particular content, lazy fetching will apply. The global flag serves the purpose to force a fetch, even if lazy is set in vendir.yaml
Signed-off-by: Fritz Duchardt <[email protected]>
Signed-off-by: Fritz Duchardt <[email protected]>
Signed-off-by: Fritz Duchardt <[email protected]>
@fritzduchardt But if we have vendir.yml:
And we run just Here |
If I read the proposal correctly, So, it wouldn't make much sense to use Does that make sense? |
I think that @Zebradil answer make sense |
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made some comments in the PR. Also, can we add some end-to-end tests to ensure we are doing the correct thing when using the lazy flag?
pkg/vendir/directory/directory.go
Outdated
"fmt" | ||
"gopkg.in/yaml.v3" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use sigs.k8s.io/yaml
instead? Just to keep it consistent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
go.mod
Outdated
@@ -27,6 +27,8 @@ require ( | |||
sigs.k8s.io/yaml v1.3.0 | |||
) | |||
|
|||
require gopkg.in/yaml.v3 v3.0.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this becomes indirect again, please let us revert this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
pkg/vendir/cmd/sync.go
Outdated
@@ -50,6 +51,7 @@ func NewSyncCmd(o *SyncOptions) *cobra.Command { | |||
|
|||
cmd.Flags().StringSliceVarP(&o.Directories, "directory", "d", nil, "Sync specific directory (format: dir/sub-dir[=local-dir])") | |||
cmd.Flags().BoolVarP(&o.Locked, "locked", "l", false, "Consult lock file to pull exact references (e.g. use git sha instead of branch name)") | |||
cmd.Flags().BoolVar(&o.Lazy, "lazy", true, "Override \"lazy\" value in directory content configuration") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can change the text here to something like:
"When this flag is set to 'false' it ignores the 'lazy' value in the directory content configuration"
Do you think it is easier to understand what the flag does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking along the same lines. It it less vague about the purpose of this option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @joaopapereira This CLI option 'lazy' (default value is true) is really confusing. With vendir 0.37.0, vendir sync --lazy=true
won't do lazy fetch. This behavior does not comply with the proposal:
https://github.com/carvel-dev/carvel/tree/develop/proposals/vendir/001-lazy-synching-on-stable-config#other-approaches-considered
This proposal should mean the CLI option --lazy default to false, and if --lazy is set to true, vendir will do lazy fetch,
Also this PR defines 'Lazy bool' as a bool instead of *bool
, so it can not be used to override the CLI option '--lazy' because it always has a default value 'false'.
type DirectoryContents struct {
Path string `json:"path"`
Lazy bool `json:"lazy,omitempty"`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jessehu The proposal was:
- to add the
lazy
option tovendir.yml
to allow skipping sync when the config is not changed, - to add the
--lazy
CLI argument to temporarily disable the effect of thelazy
option.
What you reference to is a considered approach that could've satisfied the use case but wasn't accepted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Thanks. However this 'other approach considered' makes more sense. The current code behaves a little weird:
- vendir sync --lazy=true won't do lazy fetch (--lazy default to true) since it does not overrites in lazy setting in vendir.yml
- vendir sync --lazy=false won't do lazy fetch since it overrites in lazy setting in vendir.yml
According to this behaviour, this CLI flag should be named ignoreLazySetting
or noLazy
rather than lazy
(the setting name in verdir.yml)
cmd.Flags().BoolVar(&o.Lazy, "lazy", true, "Set to 'false' it ignores the 'lazy' flag in the directory content configuration")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The alternative approach is less flexible, as it doesn't allow configuring "laziness" per directory in the vendir.yml
configuration file.
The selected name of the CLI flag is a little confusing, I agree. It might've been more explicit to use, as you mentioned, --noLazy
or alike instead of --lazy=false
.
pkg/vendir/directory/directory.go
Outdated
@@ -243,3 +278,17 @@ func maybeChmod(path string, potentialPerms ...*os.FileMode) error { | |||
|
|||
return nil | |||
} | |||
|
|||
func handleLazySync(oldConfigDigest string, newConfigDigest string, fetchLazyGlobalOverride bool, fetchLazy bool) (bool, bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We try to keep functions that are only used in a single struct internal to the structure even if they do not use the structure itself. That way we will know the scope in which we expect these functions to run.
With that in mind do you mind adding this function to the Directory struct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not at all - done
|
||
import "testing" | ||
|
||
func Test_handleLazySync(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not a fan of testing not exported functions. I understand here that this code would be more complex than testing from the outside. Is there any refactoring that can make this easier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, let's remove it and use the e2e test instead
Signed-off-by: Fritz Duchardt <[email protected]>
Signed-off-by: Fritz Duchardt <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment about the added test.
After that is solved I think we are good to merge this PR
|
||
package e2e | ||
|
||
import ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do have require
package as a dependency, and we are using it to do all the assertions in the other tests, you can see an example here.
Do you mind refactoring this test to make it similar to the other tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not at all - look much more concise now
Signed-off-by: Fritz Duchardt <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The option was proposed in [1] and implemented in [2]. [1]: https://github.com/carvel-dev/carvel/blob/develop/proposals/vendir/001-lazy-synching-on-stable-config/README.md [2]: carvel-dev/vendir#279
The option was proposed in [1] and implemented in [2]. [1]: https://github.com/carvel-dev/carvel/blob/develop/proposals/vendir/001-lazy-synching-on-stable-config/README.md [2]: carvel-dev/vendir#279 Signed-off-by: German Lashevich <[email protected]>
The option was proposed in [1] and implemented in [2]. [1]: https://github.com/carvel-dev/carvel/blob/develop/proposals/vendir/001-lazy-synching-on-stable-config/README.md [2]: carvel-dev/vendir#279 Signed-off-by: German Lashevich <[email protected]>
The option was proposed in [1] and implemented in [2]. [1]: https://github.com/carvel-dev/carvel/blob/develop/proposals/vendir/001-lazy-synching-on-stable-config/README.md [2]: carvel-dev/vendir#279 Signed-off-by: German Lashevich <[email protected]>
Implementation for: https://github.com/carvel-dev/carvel/tree/develop/proposals/vendir/001-lazy-synching-on-stable-config
Closes #278